home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 / Ham Radio 2000.iso / ham2000 / satellit / pbsv004 / pbrs232c.c < prev    next >
C/C++ Source or Header  |  1993-08-05  |  2KB  |  127 lines

  1. /* pbrs232c.c 1993.8.3 */
  2.  
  3. #include <stdio.h>
  4. #include <dos.h>
  5. #include "pbsv.h"
  6.  
  7. /*
  8.  * < initrs > initialize RS232C
  9.  */
  10. int initrs(port)
  11. int port;
  12. {
  13.     VOID set_rts(int,BOOL);
  14.     BOOL get_status(int);
  15.  
  16.     union REGS in,out;
  17.  
  18.     in.h.ah = 4;
  19.     in.x.dx = port;
  20.     int86(0x14,&in,&out);
  21.     if (out.x.ax != 0xaa55)
  22.         return(3);        /* Error: COMBIOS not exist */
  23.     set_rts(port,ON);        /* RTS on */
  24.     if (get_status(port))
  25.         return(1);
  26.     else
  27.         return(2);        /* Error: port not active */
  28. }
  29.  
  30. /*
  31.  * < get_status >
  32.  */
  33. BOOL get_status(port)
  34. int port;
  35. {
  36.     union REGS in,out;
  37.  
  38.     in.h.ah = 0x03;
  39.     in.x.dx = port;
  40.     int86(0x14,&in,&out);
  41.     return((out.h.al & 0x20) == 0x20);
  42. }
  43.  
  44. /*
  45.  * < set_rts > RTS on/off
  46.  */
  47. VOID set_rts(port,flag)
  48. int port;
  49. BOOL flag;
  50. {
  51.     union REGS in,out;
  52.  
  53.     if (flag)
  54.         in.h.ah = 6;
  55.     else
  56.         in.h.ah = 5;
  57.     in.x.dx = port;
  58.     int86(0x14,&in,&out);
  59. }
  60.  
  61. /*
  62.  * < exitrs > exit RS232C
  63.  */
  64. VOID exitrs(port)
  65. int port;
  66. {
  67.  
  68. }
  69.  
  70. /*
  71.  * < rsgetc > get RS232C
  72.  */
  73. int rsgetc(port)
  74. int port;
  75. {
  76.     int  c;
  77.     union REGS in,out;
  78.  
  79.     in.h.ah = 2;
  80.     in.x.dx = port;
  81.     int86(0x14,&in,&out);
  82.     c = out.h.al;
  83.     return(c);
  84. }
  85.  
  86. /*
  87.  * < rsputc > put RS232C
  88.  */
  89. int rsputc(port,c)
  90. int port;
  91. char c;
  92. {
  93.     union REGS in,out;
  94.  
  95.     in.h.ah = 1;
  96.     in.h.al = c;
  97.     in.x.dx = port;
  98.     int86(0x14,&in,&out);
  99. }
  100.  
  101. /*
  102.  * < rsputs > put string RS232C
  103.  */
  104. int rsputs(port,s)
  105. int port;
  106. char *s;
  107. {
  108.     while(*s)
  109.         rsputc(port,*s++);
  110. }
  111.  
  112. /*
  113.  * < check_port > check port
  114.  */
  115. BOOL check_port(port)
  116. int port;
  117. {
  118.     union REGS in,out;
  119.  
  120.     in.h.ah = 0x03;
  121.     in.x.dx = port;
  122.     int86(0x14,&in,&out);
  123.     return((out.h.ah & 0x01) > 0);
  124. }
  125.  
  126. /* pbrs232c.c */
  127.